package com.lgx.mobile.rest.topic;

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lgx.mobile.entity.TopicChatRecord;
import com.lgx.mobile.service.ITopicChatRecordService;

/**
 * 
 * @author xuyichen
 *
 */
@Controller
@RequestMapping("/getTopicChatRecord")
public class GetTopicChatRecordController {
	
	private static final Logger logger = Logger.getLogger(GetTopicChatRecordController.class);

	@Autowired
	ITopicChatRecordService topicChatRecordService;

	public ITopicChatRecordService getTopicChatRecordService() {
		return topicChatRecordService;
	}

	/**
	 * 话题聊天记录查询
	 * @param topicId topicId is key
	 * @return 话题内所有用户的聊天记录集合；0：该话题没有聊天记录；1：参数异常，有参数为空
	 */
	@RequestMapping(value="/{topicId}",method=RequestMethod.GET)
	@ResponseBody
	public Object getTopicChatRecord(@PathVariable("topicId") String topicId){
		if(StringUtils.isNotBlank(topicId)){
			List<TopicChatRecord> topicChatRecordList = getTopicChatRecordService().findTopicChatRecordListByTopicId(Long.parseLong(topicId));
			if(topicChatRecordList.size() != 0){
				return topicChatRecordList;
			}else{
				if(logger.isDebugEnabled()){
					logger.debug("getTopicChatRecord faild topicId is error");
				}
//				"getTopicChatRecord faild please check topicId is exists";
				return "0";
			}
		}else{
			if(logger.isDebugEnabled()){
				logger.debug("getTopicChatRecord faild topicId is not filled");
			}
//		    "getTopicChatRecord faild please check topicId is filled";
			return "1";
		}
	}
}
